package com.bnlr.lrparking.util;

import android.view.View;
import android.widget.ImageView;
import android.widget.ZoomControls;

import com.baidu.location.LocationClientOption;
import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.MapStatusUpdate;
import com.baidu.mapapi.map.MapStatusUpdateFactory;
import com.baidu.mapapi.map.MyLocationConfiguration;
import com.baidu.mapapi.map.TextureMapView;
import com.baidu.mapapi.model.LatLng;
import com.bnlr.lrparking.constant.Params;

/**
 * Created by hp on 2017/7/14.
 * 百度地图封装
 */

public class BDMapUtils {

    public static final float MAX_MAP_LEVEL = 19f;
    public static final float MIN_MAP_LEVEL = 6f;
    /**
     * 配置地图view
     * @param bmapView
     */
    public void configMap(TextureMapView bmapView){
        bmapView.showScaleControl(false);
        bmapView.showZoomControls(false);
        View child = bmapView.getChildAt(1);
        boolean isCorrect = child != null && (child instanceof ImageView || child instanceof ZoomControls);
        if (isCorrect) {
            child.setVisibility(View.VISIBLE);
        }
    }

    /**
     * 设置定位参数
     * @return
     */
    public LocationClientOption locationOption() {
        LocationClientOption option = new LocationClientOption();
        option.setOpenGps(true); // 打开gps
        option.setCoorType("bd09ll"); // 设置坐标类型
        option.setScanSpan(0);//    单次定位
        option.setAddrType("all");
        option.setIsNeedAddress(true);
        return option;
    }

    /**
     * 移动到指定地点
     * @param mBaiDuMap
     */
    public void moveMapStatus (BaiduMap mBaiDuMap) {
        LatLng ll = new LatLng(Params.CurrentLat, Params.CurrentLon);
        //定位点移至中心
        MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(ll);
        mBaiDuMap.animateMapStatus(u);
    }

    /**
     * 配置地图
     * @param mBaiDuMap
     */
    public void initBaiDuMap(BaiduMap mBaiDuMap) {
        mBaiDuMap.animateMapStatus(MapStatusUpdateFactory.zoomTo(18));
        mBaiDuMap.setMyLocationConfiguration(new MyLocationConfiguration(
                MyLocationConfiguration.LocationMode.FOLLOWING, true, null));
        // 开启定位图层
        mBaiDuMap.setMyLocationEnabled(true);
    }
}
